import java.net.InetAddress;

import edu.ucla.cs.typecast.net.NetUtil;
import edu.ucla.cs.typecast.rmi.TypeCastClient;
import edu.ucla.cs.typecast.scope.HostScope;
import edu.ucla.cs.typecast.scope.TTLScope;


public class PingClient {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try { 
        	Options options = new Options(args); 
        	TypeCastClient client = new TypeCastClient(); 
        	String host = options.getOption("-host"); 
        	if (host != null) { 
        		HostScope hostScope = new HostScope(InetAddress.getByName(host));  
        		client.setScope(hostScope);
        	}
        	
        	String ttl = options.getOption("-ttl"); 
        	if (ttl != null) { 
        		TTLScope ttlScope = new TTLScope(Integer.parseInt(ttl)); 
        		client.setScope(ttlScope); 
        	}
        	PingService pingService = client.getInvocationHandler(PingService.class);         	
            pingService.ping(NetUtil.getLocalHost(), options.getParameter(0)); 
        } catch(Throwable t) { 
            t.printStackTrace(); 
        }
    }

}
